package com.hg.thread;

/**
 * @Author: skh
 * @Date: 2019/12/20 11:09
 * @Description:
 */
public class SellTicketDemo {

    public static void main(String[] args) throws Exception{
        //Ticket ticket = new Ticket();
        //new Thread(()->{
        //    for (int i = 0; i < 50; i++) {
        //        ticket.addTicket();
        //    }
        //}, "售票员A").start();
        //
        //
        //new Thread(()->{
        //    for (int i = 0; i < 50; i++) {
        //        ticket.addTicket();
        //    }
        //}, "售票员B").start();
        //
        //new Thread(()->{
        //    for (int i = 0; i < 50; i++) {
        //        ticket.addTicket();
        //    }
        //}, "售票员C").start();


        TIcket2 tIcket2 = new TIcket2();

        new Thread(()->{
            for (int i = 0; i < 10; i++) {
                try {
                    tIcket2.add();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "A").start();

        new Thread(()->{
            for (int i = 0; i < 10; i++) {
                try {
                    tIcket2.decrease();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "B").start();

        new Thread(()->{
            for (int i = 0; i < 10; i++) {
                try {
                    tIcket2.add();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "C").start();

        new Thread(()->{
            for (int i = 0; i < 10; i++) {
                try {
                    tIcket2.decrease();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "D").start();
    }
}
